<?php 
class MAuth extends CI_Model {

    function __construct()
    {
        parent::__construct();
    }
    
    function login($username,$password)
    {
        $this->db->select('u.id');
        $this->db->join('users_groups as ug', 'ug.user_id = u.id', 'left');
        $this->db->join('groups as g', 'g.id = ug.group_id', 'left');
        $this->db->where('u.username',$username);
        $this->db->where('u.password',$password);
        $this->db->where('g.name','Admin');        
        $query = $this->db->get('users as u');
        if ($query->num_rows()) {
            return 1;    
        } else {
            return 0;
        }       
    }
    
    function isLoggedIn()
    {
        if ($this->session->userdata('username') && $this->session->userdata('password')) {
            return 1;    
        } else {
            return 0;
        }
    }
}
